//
// Created by 26364 on 2025/10/28.
//

#ifndef BOOTLOADER_MY_INFLASH_H
#define BOOTLOADER_MY_INFLASH_H
#include "main.h"
/* STM32H743IIT6 内部FLASH扇区定义（Bank 1，共1MB）
   地址范围：0x08000000 - 0x080FFFFF（2MB总FLASH的前1MB，后1MB为Bank 2，此处暂不涉及） */
#define ADDR_FLASH_SECTOR_0_BANK1       ((uint32_t)0x08000000) /* 128 Kbytes */
#define ADDR_FLASH_SECTOR_1_BANK1       ((uint32_t)0x08020000) /* 128 Kbytes */
#define ADDR_FLASH_SECTOR_2_BANK1       ((uint32_t)0x08040000) /* 128 Kbytes */
#define ADDR_FLASH_SECTOR_3_BANK1       ((uint32_t)0x08060000) /* 128 Kbytes */
#define ADDR_FLASH_SECTOR_4_BANK1       ((uint32_t)0x08080000) /* 128 Kbytes */
#define ADDR_FLASH_SECTOR_5_BANK1       ((uint32_t)0x080A0000) /* 128 Kbytes */
#define ADDR_FLASH_SECTOR_6_BANK1       ((uint32_t)0x080C0000) /* 128 Kbytes */
#define ADDR_FLASH_SECTOR_7_BANK1       ((uint32_t)0x080E0000) /* 128 Kbytes */
#define ADDR_FLASH_SECTOR_END_BANK1     ((uint32_t)0x08100000) /* Bank 1结束地址（不含） */
#define ADDR_FLASH_SYS_BANK1            ((uint32_t)0x1FF00000) /* 128 Kbytes */


#define ADDR_FLASH_SECTOR_0_BANK2       ((uint32_t)0x08100000) /* 128 Kbytes */
#define ADDR_FLASH_SECTOR_1_BANK2       ((uint32_t)0x08120000) /* 128 Kbytes */
#define ADDR_FLASH_SECTOR_2_BANK2       ((uint32_t)0x08140000) /* 128 Kbytes */
#define ADDR_FLASH_SECTOR_3_BANK2       ((uint32_t)0x08160000) /* 128 Kbytes */
#define ADDR_FLASH_SECTOR_4_BANK2       ((uint32_t)0x08180000) /* 128 Kbytes */
#define ADDR_FLASH_SECTOR_5_BANK2       ((uint32_t)0x081A0000) /* 128 Kbytes */
#define ADDR_FLASH_SECTOR_6_BANK2       ((uint32_t)0x081C0000) /* 128 Kbytes */
#define ADDR_FLASH_SECTOR_7_BANK2       ((uint32_t)0x081E0000) /* 128 Kbytes */
#define ADDR_FLASH_SECTOR_END_BANK2     ((uint32_t)0x08200000) /* Bank 2结束地址（不含） */
#define ADDR_FLASH_SYS_BANK2            ((uint32_t)0x1FF40000) /* 128 Kbytes */

#define My_Date  ADDR_FLASH_SECTOR_3_BANK1  //128k
#define APP_RUN  ADDR_FLASH_SECTOR_4_BANK1  //128*2
#define APP1  ADDR_FLASH_SECTOR_3_BANK2     //128*2
#define APP2  ADDR_FLASH_SECTOR_5_BANK2     //128*2

uint8_t InternalFlash_Erase(uint32_t startAddr, uint32_t size, uint8_t bank);
uint8_t InFlash_Write(uint32_t startAddr, uint8_t* data, uint32_t size);
#endif //BOOTLOADER_MY_INFLASH_H
